﻿package code
{
	import flash.display.*;
	import flash.events.*;
	import gemini.utils.*
	import caurina.transitions.*
	public class NavButton extends Sprite
	{
		var img;
		var mainframe;
		public var mynum;
		public var sx;
		public var modinfo;
		var loadmod;
		var myicon;
		var myshadow;
		var myreflection;
		
		public function NavButton(mf)
		{
			mainframe = mf;			
			loadmod=new loadingmod();
			addChild(loadmod);
			//addEventListener(Event.ADDED_TO_STAGE,addListeners);
		}
		public function init()
		{
			modinfo.addOnComplete(getModInfo);
			
		}
		private function addListeners(e)
		{
			trace("adding events");
			//stage.addEventListener(MouseEvent.MOUSE_MOVE,moveMe);
			img.btn.addEventListener(MouseEvent.MOUSE_DOWN,pressMe);
			img.btn.addEventListener(MouseEvent.MOUSE_OVER,overMe);
			img.btn.addEventListener(MouseEvent.MOUSE_OUT,outMe);
		}
		public function getModInfo(e)
		{
			modinfo=e;
			try
			{
			img=new btnclip();
			
			//var cls=mainframe.mainframe.getClass(e.clip,"modicon");
			myicon=e.clip.ModuleIcon();
			myshadow=e.clip.ModuleIcon();
			myreflection=e.clip.ModuleIcon();
			var scale=216/256;
			myicon.scaleX=scale;
			myicon.scaleY=scale;
			myicon.x=20;
			myicon.y=20;
			myreflection.scaleX=scale;
			myreflection.scaleY=scale;
			myreflection.x=20
			myreflection.y=20
			
			myicon.cacheAsBitmap=true;
			myicon.smoothing=true;
			img.icon.iconimg.holder.addChild(myicon);
			img.icon.iconshadow.addChild(myshadow);
			img.icon.iconreflection.addChild(myreflection);
			img.icon.iconreflection.cacheAsBitmap=true;
			img.icon.maska.cacheAsBitmap=true;
			img.icon.iconreflection.mask=img.icon.maska;
			removeChild(loadmod);
			
			img.icon.iconimg.cacheAsBitmap=true;
			img.icon.iconimg.smoothing=true;
			addChild(img);
			scale=30/img.width;
			img.scaleX=scale;
			img.scaleY=scale;
			
			Filters.addFilters(myicon,"DropShadowFilter,quality:3,distance:1");
			mainframe.setButtons();
			addListeners(0);
			//
			//
			//
			img.icon.iconimg.sx=img.icon.iconimg.x
			img.icon.iconimg.sy=img.icon.iconimg.y
			//
			img.icon.iconreflection.sx=img.icon.iconreflection.x
			img.icon.iconreflection.sy=img.icon.iconreflection.y
			}
			catch(ee)
			{
				trace("there is not icon class in "+e.mod.clip);
				trace("error:"+ee);
			}
			
			
		}
		private function removeListeners(e)
		{

		}
		private function pressMe(e)
		{
			mainframe.focusMod(modinfo);
		}
		private function outMe(e)
		{
			mainframe.mainframe.hideInfo();
			Tweener.addTween
			(
			 	img.icon.iconimg,
				{
					y:img.icon.iconimg.sy,
					time:.2,
					transition:"easeInOutQuad"
				}
			 )
			Tweener.addTween
			(
			 	img.icon.iconreflection,
				{
					y:img.icon.iconreflection.sy,
					time:.2,
					transition:"easeInOutQuad"
				}
			 )
			
		}
		private function overMe(e)
		{
			mainframe.mainframe.showShortInfo(modinfo.clip);
			
			Tweener.addTween
			(
			 	img.icon.iconimg,
				{
					y:img.icon.iconimg.y-70,
					time:.2,
					transition:"easeInOutQuad"
				}
			 )
			Tweener.addTween
			(
			 	img.icon.iconreflection,
				{
					y:img.icon.iconreflection.sy+70,
					time:.2,
					transition:"easeInOutQuad"
				}
			 )
			
		}
		private function moveMe(e)
		{
			mainframe.onMove(this);

		}

	}

}